﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;
using Icms.Resources;

namespace Icms.WebUI.Controllers
{
    public class RoomIdAjaxDropdownController : Controller
    {
        private readonly IRepo<Room> r;

        public RoomIdAjaxDropdownController(IRepo<Room> r)
        {
            this.r = r;
        }
        public ActionResult GetItems(Guid? key)
        {
            var list = new List<SelectListItem> { new SelectListItem { Text = Mui.not_selected, Value = "" } };
            

            var result = r.GetAll();

            list.AddRange(result.Select(o => new SelectListItem
                                                 {
                                                     Text = o.Title,
                                                     Value = o.Id.ToString(),
                                                     Selected = o.Id == key
                                                 }));
            return Json(list);
        }
    }
}